<template>
    <base-breadcrumb>
        <searchData :search-data="searchArr" @search="search"/>
        
        <a-card>
          <list-table
            ref="table"
            class="export-table"
            :columns="columns"
            :request="loadData"
            :showTotalSize="false"
            :statisticsConfig="{use: true, temp: statisticsTemp}"
          >
            
            <template slot="prefix" slot-scope="ref">
              <a-button @click="handleDetial('add')" type="primary" v-btnPermission="'tm_009_add_01'">新增</a-button>
            </template>
            
            <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
            <span slot="orgName" slot-scope="text, record, index">{{ text == '西南公司' ? '总部机关' : text }}</span>
            
            <!-- 操作 -->
            <template slot="operation" slot-scope="text, record">
                <MoreButton>
              <a @click="handleDetial('view', record)" v-btnPermission="'tm_009_loo_03'">查看会议</a>
              <a v-if="record.auditStatus == 'DRAFT'&&hideBuquBtn()" @click="handleDetial('edit', record)">编辑</a>
              <a v-if="record.auditStatus == 'DRAFT'&&hideBuquBtn()" @click="handleDelete(record)">删除</a>
                </MoreButton>
            </template>
          </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import Ellipsis from '@/components/Ellipsis'
import { getProgramMeetList, getProgramMeetTotal, programMeetDel } from '@/api/technical/meeting'
import { getAllBranchCompany } from '@/api/commons'
const columns = [
    {
        title: '序号',
        width: '65px',
        scopedSlots: { customRender: 'serial' },
    },
    {
        title: '所属组织机构',
        dataIndex: 'orgName',
        scopedSlots: { customRender: 'orgName' },
    },
    {
        title: '会议名称',
        dataIndex: 'meetingName',
    },
    {
        title: '主持人',
        dataIndex: 'speaker',
    },
    {
        title: '召开时间',
        dataIndex: 'meetDate',
    },
    {
        title: '状态',
        dataIndex: 'statusSer',
    },
    {
        title: '操作',
        dataIndex: 'operation',
        fixed: 'right',
        width: '230px',
        scopedSlots: { customRender: 'operation' },
    },
]
export default {
    name:'a'+Date.now(),
    components: {
        SelectSubCompany,
        SelectProject,
        Ellipsis
    },
    data() {
        this.columns = columns
        return {
            loadData: (parameter) => {
              let that = this
              const requestParameters = Object.assign({ needCount: true }, parameter, { query: this.queryParam })
              getProgramMeetTotal(requestParameters)
              .then((res) => {
                  this.loading.isTable = false
                  this.from = res.data
              })
              .catch(() => {
                  this.loading.isTable = false
              })
              return getProgramMeetList(requestParameters).then((res) => {
                return res
              })
            },
            loading: {
                isTable: false,
            },
            queryParam: {},
            from: {
              meetNum: '0',
              szNum: '0',
              anum: '0',
              bnum: '0',
              szApprove: '0%'
            },
            statisticsTemp: () => {
              // 联审会议次数：8 | 施组方案总数量：8 |   A类方案数：2 |   B类方案数：2 |   施组方案联审率：80% |
                return (
                    <span>
                      <span>联审会议次数：<a> { this.from.meetNum } </a></span>
                      <span><span style="margin: 0 5px">|</span>施组方案总数量：<a> { this.from.szNum }</a></span>
                      <span><span style="margin: 0 5px">|</span>A类方案数：<a> { this.from.anum } </a></span>
                      <span><span style="margin: 0 5px">|</span>B类方案数：<a> { this.from.bnum } </a></span>
                      <span><span style="margin: 0 5px">|</span>施组方案联审率：<a> { this.from.szApprove } </a></span>
                      <span></span>
                    </span>
                )
            },
            companyList: []
        }
    },
    computed: {
      ownOrgList() {
        let levels = [...this.$userInfo().employee.levels]
        let ownOrg = levels.filter((v) => {
          return v.code === 'CO' || v.code === 'BC'
        })
        ownOrg.forEach((v) => {
          if (v.code == 'CO') v.name = '总部机关'
          v.label = v.name
          v.value = v.id
        })
        return ownOrg
      },
      searchArr() {
        return [
          {
            name: '所属组织机构',
            value: 'orgId',
            placeholder: '请选择',
            type: 'select',
            // request: this.querCompany,
            data: this.companyList
          },
          // 搜索框
          // {
          //   name: '所属组织机构',
          //   value: 'orgId',
          //   placeholder: '请选择',
          //   type: 'select',
          //   data: this.ownOrgList
          // },
          {
            name: '会议名称',
            value: 'name',
            placeholder: '关键字',
            type: 'input',
          },
          {
            name: '召开时间',
            value: 'recordTime',
            type: 'dateRange',
            attr: {
              rangeFormat: ['recordDateBegin', 'recordDateEnd'],
            }
          },
          {
            name: '主持人',
            value: 'mainName',
            placeholder: '关键字',
            type: 'input',
          },
          {
            name: '状态',
            value: 'status',
            placeholder: '关键字',
            type: 'select',
            // 未提交 已提交 已结束
            data: [
              {
                label: '未提交',
                value: 'DRAFT'
              },
              {
                label: '已提交',
                value: 'SUBMITTED'
              },
              {
                label: '已结束',
                value: 'PAST'
              }
            ]
          }
        ]
      }
    },
    created() {
      this.querCompany()
    },
    methods: {
        querCompany() {
          getAllBranchCompany({tagCodes: ['BC']}).then((res) => {
            let co = [{
              id: "53085e2c9f1f4685801ef31994f57c49",
              name: "总部机关",
            }]
            res.data = [ ...co, ...res.data ]
            let datas = res.data.map((item, index) => {
              return { label: item.name, value: item.id }
            })
            this.companyList = datas
          })
        },
        search(values) {
          this.queryParam = { ...values }
          this.$refs.table.refresh()
        },
        handleDelete(e) {
            let that = this
            that.$confirm({
                title: '温馨提示',
                content: '确定是否删除数据？',
                okText: '确认',
                okType: 'danger',
                cancelText: '取消',
                onOk() {
                    return programMeetDel(e.id)
                        .then((res) => {
                            that.$message.success('删除成功！')
                            that.$refs.table.refresh()
                        })
                        .catch((res) => {
                            that.$message.warning('删除失败！')
                        })
                },
            })
        },
        handleDetial(type, record) {
          let query = { type }
          if (type !== 'add') {
            query.id = record.id
          }
          this.$router.push({
              path: '/technical/reviewMeeting/programReview/edit',
              query,
          })
        },
    },
}
</script>

<style lang="less">
.not-submit {
    display: inline-block;
    padding: 0;
    li {
        list-style: none;
        color: red;
    }
}
.submitted {
    display: inline-block;
    padding: 0;
    li {
        list-style: none;
        color: green;
    }
}
</style>
